//
//  NSAttributedString+AttributedStringConfig.m
//  MyFunctionDemo
//
//  Created by Ting Han on 2017/9/1.
//  Copyright © 2017年 Ting Han. All rights reserved.
//

#import "NSAttributedString+AttributedStringConfig.h"

@implementation NSAttributedString (AttributedStringConfig)

+ (instancetype)attributedStringWithString:(NSString *)string config:(void (^)(NSMutableArray<AttributedStringConfig *> *))configBlock{
    
    NSMutableArray      *array                = nil;
    NSMutableDictionary *attributesDictionary = nil;
    if (configBlock) {
        array                = [NSMutableArray array];
        attributesDictionary = [NSMutableDictionary dictionary];
        //把一个空的Array传递给调用者。调用者在里面添加东西
        configBlock(array);
        
        [array enumerateObjectsUsingBlock:^(AttributedStringConfig *obj, NSUInteger idx, BOOL * _Nonnull stop) {
            
            [attributesDictionary setObject:obj.attributeValue forKey:obj.attributeName];
        }];

    }
    NSAttributedString *attributedString = [[NSAttributedString alloc]initWithString:string attributes:attributesDictionary];
    return attributedString;
}



@end
